<!--
 * @Description: 我的设置
 * @Author: Kerwin
 * @Date: 2025-03-31 17:36:37
 * @LastEditTime: 2025-08-05 16:04:52
 * @LastEditors:  Please set LastEditors
-->

<template>
  <view class="setting">
    <view class="topBox">
      <u-cell-group :border="false">
        <u-cell-item
          title="个人信息"
          style="font-weight: 700; color: #000"
        ></u-cell-item>
      </u-cell-group>
      <u-cell-group :border="false">
        <u-cell-item
          title="收货地址"
          style="font-weight: 700; color: #000"
          @click="handleGoAddress"
        ></u-cell-item>
      </u-cell-group>
      <u-cell-group :border="false">
        <u-cell-item
          title=""
          style="font-weight: 700; color: #000"
        ></u-cell-item>
      </u-cell-group>

      <!-- <u-cell-group :border="false">
                <u-cell-item title="绑定支付宝" style="font-weight: 700; color: #000;"></u-cell-item>
            </u-cell-group> -->
      <van-cell
        title="手机号"
        style="font-weight: 700; color: #000; font-size: 28rpx"
      >
        <template #right-icon>
          <text v-if="phoneText != '绑定手机号'">{{ phoneText }}</text>
          <text v-else @click="toBindPhone">绑定手机号</text
          ><u-icon
            v-if="!phoneText"
            style="color: #969799"
            name="arrow-right"
          ></u-icon>
        </template>
      </van-cell>

      <!-- <u-cell-group :border="false">
                <u-cell-item title="建议反馈" style="font-weight: 700; color: #000;"></u-cell-item>
            </u-cell-group> -->
      <!-- <u-cell-group :border="false">
                <u-cell-item title="用户注销" style="font-weight: 700; color: #000;"></u-cell-item>
            </u-cell-group> -->

      <van-cell
        title="服务热线"
        style="font-weight: 700; color: #000; font-size: 28rpx"
      >
        <!-- 使用 right-icon 插槽来自定义右侧图标 -->
        <template #right-icon>
          <text style="color: red">400-638-1238</text>
        </template>
      </van-cell>
      <!-- <u-cell-group :border="false">
                <u-cell-item title="关于我们" style="font-weight: 700; color: #000;"></u-cell-item>
            </u-cell-group> -->
      <u-cell-group :border="false">
        <u-cell-item
          @click="show = true"
          title="切换模式"
          style="font-weight: 700; color: #000"
        ></u-cell-item>
      </u-cell-group>
    </view>

    <u-button shape="square" :ripple="true" @tap="loginOutFn" type="primary">
      退出登录</u-button
    >

    <u-popup v-model="show" mode="bottom" border-radius="24">
      <view
        class="itemSY"
        :class="{ active: index == currentIndex }"
        @click="changeList(item, index)"
        v-for="(item, index) in shopTypeAllList"
        >{{ item.name }}</view
      >
    </u-popup>
  </view>
</template>

<script setup lang="ts">
import { useUserStore, useChatStore } from '@/store'
import { ref, computed } from 'vue'
import { route } from '@/utils/common'
import { onShow, onLoad } from '@dcloudio/uni-app'
import { userApi } from '@/api'

//初始数据
const userStore = useUserStore()
const phoneText = ref('')
const show = ref(false)
const currentIndex = ref(0)
const shopTypeAllList = ref([
  { name: '黑银', id: 0 },
  { name: '花积分', id: 1 },
  { name: '链动模式', id: 1 },
  { name: '酒慕网', id: 3 },
  { name: '鑫复来', id: 4 },
  { name: '长来科技', id: 6 }
])
const hyType = ref({ name: '黑银', id: 0 })

//跳转到绑定手机号·
const toBindPhone = () => {
  uni.navigateTo({
    url: '/pages/physicalShopCheck/bindPhone'
  })
}

//切换门店
const changeList = (item: any, index: any) => {
  currentIndex.value = index

  uni.switchTab({
    url: `/pages/index/index`
  })
  uni.setStorageSync('hyType', JSON.stringify(item))
  show.value = false
}

//获取用户数据  phone.replace(/^(\d{3})\d{4}(\d{4})$/, '$1****$2')
const getUserDetailInfo = async () => {
  const { data } = await userApi.userInfo()
  if (data.phone) {
    phoneText.value = data.phone.replace(/^(\d{3})\d{4}(\d{4})$/, '$1****$2')
  } else {
    phoneText.value = '绑定手机号'
  }
}

// 登录退出
const loginOutFn = () => {
  uni.showLoading({ title: '', mask: true })
  userStore.syncClearToken()
  userStore.syncClearUserInfo()
  window.location.href = 'https://wap.blacksilverscore.com/#/pages/mine/index'
  uni.hideLoading()
  uni.removeStorageSync('hyType')
}

const handleGoAddress = () => {
  uni.navigateTo({
    url: `/packageB/pages/addressList/index?type=mine`
  })
}
//页面初次  确定模式
onShow(async () => {
  if (uni.getStorageSync('hyType')) {
    hyType.value = JSON.parse(uni.getStorageSync('hyType'))
  } else {
    hyType.value = { name: '黑银', id: 0 }
  }
  currentIndex.value = hyType.value.id
})
onLoad(() => {
  getUserDetailInfo()
})
</script>

<style scoped>
.setting {
  height: 100vh;
  background-color: #fff;
  padding: 0 20rpx;
}

.topBox {
  margin-bottom: 50rpx;
}

.itemSY {
  height: 100rpx;
  line-height: 100rpx;
  border-bottom: 5rpx solid #fff;
  text-align: center;
  background-color: #f9f9f9;
}

.active {
  color: #fff;
  background-color: #f28b54;
}
</style>
